package com.gitee.kenewstar.migration.api;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.gitee.kenewstar.migration.entity.CommonResult;
import com.gitee.kenewstar.migration.entity.Lov;
import com.gitee.kenewstar.migration.entity.LovViewHeader;
import com.gitee.kenewstar.migration.service.migration.LovMigrationService;
import com.gitee.kenewstar.migration.util.ExcelUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author kenewstar
 */
@DS("dev")
@RestController
@RequestMapping("/lov")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class LovApi {

    private final LovMigrationService lovMigrationService;

    @PostMapping("/lov-migration")
    public List<CommonResult> lovMigration(@RequestBody List<String> lovCodeList, @RequestParam(required = false) Long tenantId) {
        return this.lovMigrationService.lovMigration(lovCodeList, tenantId);
    }

    @PostMapping("/lov-view-migration")
    public List<CommonResult> lovViewMigration(@RequestBody List<String> lovViewCodeList, @RequestParam(required = false) Long tenantId) {
        return this.lovMigrationService.lovViewMigration(lovViewCodeList, tenantId);
    }

    @PostMapping("/excel-lov-migration")
    public List<CommonResult> excelLovMigration(@RequestPart("file") MultipartFile file) {
        return this.lovMigrationService.excelLovMigration(ExcelUtil.filterReadData(file, Lov.class));
    }

    @PostMapping("/excel-lov-view-migration")
    public List<CommonResult> excelLovViewMigration(@RequestPart("file") MultipartFile file) {
        return this.lovMigrationService.excelLovViewMigration(ExcelUtil.filterReadData(file, LovViewHeader.class));
    }

}
